export default {
  methods: {
    // 检查是否已登录
    isLoggedIn() {
      const token = uni.getStorageSync('token')
      const userId = uni.getStorageSync('userId')
      return !!(token && userId)
    },

    // 跳转到登录页
    toLogin() {
      const pages = getCurrentPages()
      const currentPage = pages[pages.length - 1]
      const url = currentPage ? currentPage.route : ''
      
      // 保存当前页面路径，登录后可以跳回来
      if (url && url !== 'pages/login/login') {
        uni.setStorageSync('redirect', '/' + url)
      }

      uni.showToast({
        title: '请先登录',
        icon: 'none'
      })
      
      setTimeout(() => {
        uni.navigateTo({
          url: '/pages/login/login'
        })
      }, 1500)
    }
  }
} 